# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>
# Contributor: Mario Finelli <mario at finel dot li>
# Contributor: Andy Weidenbaum <archbaum at gmail dot com>

_gemname='ruby-progressbar'
pkgname="ruby-${_gemname}"
pkgver=1.11.0
pkgrel=3
pkgdesc='Flexible text progress bar library for Ruby'
arch=('any')
url="https://github.com/jfelchner/${_gemname}"
license=('MIT')
depends=('ruby')
#checkdepends=('ruby-rspec')
options=('!emptydirs')
source=("${url}/archive/releases/v${pkgver}/${_gemname}-${pkgver}.tar.gz")
sha512sums=('5a5c8a6af410746ef601821ec171933d781d32bfb7cb5f67f9cf877824a399941c11be69bb74380941f2271f6f5139928599881441f88860a71f8b7f7b55d4b4')

prepare() {
  cd "${_gemname}-releases-v${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"

  sed --in-place '/cert_chain/d' "${_gemname}.gemspec"
  sed --in-place '/signing_key/d' "${_gemname}.gemspec"
}

build() {
  cd "${_gemname}-releases-v${pkgver}"

  gem build "${_gemname}.gemspec"
}

# needs https://rubygems.org/gems/rspectacular to work
#check() {
#  cd "${_gemname}-releases-v${pkgver}"
#
#  rspec
#}

package() {
  cd "${_gemname}-releases-v${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}/${_gemdir}" \
    --bindir "${pkgdir}/usr/bin" \
    "${_gemname}-${pkgver}.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "${pkgdir}/${_gemdir}/cache/" \
    "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/vendor/" \
    "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext/"

  find "${pkgdir}/${_gemdir}/gems/" \
    -type f \
    \( \
      -iname "*.o" -o \
      -iname "*.c" -o \
      -iname "*.so" -o \
      -iname "*.time" -o \
      -iname "gem.build_complete" -o \
      -iname "Makefile" \
    \) \
    -delete

  find "${pkgdir}/${_gemdir}/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete

  install --verbose -D --mode=0644 LICENSE.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}

# vim: set ts=2 sw=2 et:
